package 实践.class_08.Demo_02;

abstract class Employee {
    //姓名
    private  String name;

    public Employee(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
    public abstract double earnings();
    @Override
    public String toString() {
        return "Employee:"+ name + '\n';
    }
}
class Boss extends Employee{
    //固定周工资
    private double weeklySalary;
    //构造方法
    public Boss(String name, double weeklySalary) {
        super(name);
        this.weeklySalary = weeklySalary;
    }
    /**
     * 获取
     * @return weeklySalary
     */
    public double getWeeklySalary() {
        return weeklySalary;
    }

    /**
     * 设置
     * @param weeklySalary
     */
    public void setWeeklySalary(double weeklySalary) {
        this.weeklySalary = weeklySalary;
    }


    @Override
    public double earnings() {
        return weeklySalary;
    }
    @Override
    public String toString() {
        super.getName();
        return "Boss:"+this.getName() ;
    }
}
class CommissionWorker extends Employee {
    //工资
    private double salary;
    //佣金
    private double commission;
    //销售数量
    private int quantity;

    //构造方法
    public CommissionWorker(String name, double salary, double commission, int quantity) {
        super(name);
        this.salary = salary;
        this.commission = commission;
        this.quantity = quantity;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public double getCommission() {
        return commission;
    }

    public void setCommission(double commission) {
        this.commission = commission;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    @Override
    public double earnings() {
        return salary + commission * quantity;
    }
    @Override
    public String toString() {
        super.getName();
        return "CommissionWorker:"+this.getName() ;
    }
}
class PieceWorker extends Employee {
    //每件产品工资
    private double wagePerPiece;
    //生产数量
    private int quantity;
    //构造方法
    public PieceWorker(String name, double wagePerPiece, int quantity) {
        super(name);
        this.wagePerPiece = wagePerPiece;
        this.quantity = quantity;
    }

    public double getWagePerPiece() {
        return wagePerPiece;
    }

    public void setWagePerPiece(double wagePerPiece) {
        this.wagePerPiece = wagePerPiece;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    @Override
    public double earnings() {
        return wagePerPiece*quantity;
    }
    @Override
    public String toString() {
        super.getName();
        return "PieceWorker:"+this.getName() ;
    }
}
class HourlyWorker extends Employee {
    //每小时工资
    private double wage;
    //工作小时数
    private double hours;
    //构造方法
    public HourlyWorker(String name, double wage, double hours) {
        super(name);
        this.wage = wage;
        this.hours = hours;
    }

    public void setWage(double wage) {
        this.wage = wage;
    }

    public void setHours(double hours) {
        this.hours = hours;
    }

    @Override
    public double earnings() {
        if (hours <= 40) {
            return wage * hours;
        } else {
            return 40 * wage + (hours - 40) * wage * 1.5;
        }
    }
    @Override
    public String toString() {
        super.getName();
        return "HourlyWorker:"+this.getName() ;
    }
}
